package com.echo.im.offlinePush.config;

import com.echo.im.common.contant.MQConstants;
import org.springframework.amqp.core.*;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: echo
 * @time: 2024-08-20
 */
@Configuration
public class RabbitMQConfig {

    @Bean
    public TopicExchange echoStoreExchange() {
        return ExchangeBuilder
                .topicExchange(MQConstants.ECHO_STORE_EXCHANGE)
                .durable(true)
                .build();
    }

    @Bean
    public Queue offlineMessagePushQueue() {
        return new Queue(MQConstants.OFFLINE_MESSAGE_PUSH_QUEUE);
    }

    @Bean
    Binding offlineMessageBinding(TopicExchange echoStoreExchange, Queue offlineMessagePushQueue) {
        return BindingBuilder
                .bind(offlineMessagePushQueue)
                .to(echoStoreExchange)
                .with(MQConstants.OFFLINE_MESSAGE_TOPIC);
    }

}
